Fix method calls for PHP objects wrapped in variant #16945
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As is, methods of PHP can never be called, because we're first trying to read the property with the name of the method.
We fix this by first checking for
DISPATCH_METHOD
and treat that as method call, if the method would be callable. Only otherwise we try to access the respective property.It needs to be noted that this breaks code which accesses a property of an object, which defines a method of the same name. However, instances of such classes should never be wrapped in variants, because this can't be distinguished by COM anyway.
This is a follow-up to #16331.
Note that this supports COM style where property access and function calls are not necessarily distinguished (VB doesn't, for example). Distinguishing method calls from property accesses would be possible, but might have issues regarding interoperability.
Also note that when accessing properties and calling functions, the names are taken unmodifed, and then looked up as they are stored as object property or method; that means variable need to use the case they've been declared with, and functions always needs to be lower-cased. Fixing this appears to be trivial, but would further reduce the available namespace (usually there can be different PHP properties with the same name in when using different case). Still, it might be a good idea to convert to lower-case, and to clearly document that such PHP objects are not supposed to have properties/methods with the same name in different letter case (since currently that already doesn't work cleanly; if there is a property and a method with the same name, only the property gets a disp ID, but one can still call the method).